﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebsiteBanSachOnline
{
    public partial class Home : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            BookOnlineDataContext book = new BookOnlineDataContext();
            var dsdm = from dm in book.DanhMucs
                       select new { dm.MaDanhMuc, dm.TenDanhMuc };
            ListDanhMuc.Items.Clear();
            ListDanhMuc.DisplayMode = BulletedListDisplayMode.HyperLink;
            foreach (var obj in dsdm)
            {
                ListItem li = new ListItem(obj.TenDanhMuc, "~/TimKiemSach.aspx?Loai=DanhMuc&MaDanhMuc="+obj.MaDanhMuc);
                ListDanhMuc.Items.Add(li);
                
            }
            txtGiaTriTimKiem.Attributes.Add("onclick","clearTextBox(this.id)");
            txtGiaTriTimKiem.Attributes.Add("onblur","fillBack(this.id)");
            
        }

        protected void btnTimKiem_Click(object sender, EventArgs e)
        {
            if (txtGiaTriTimKiem.Text == "Nhập vào giá trị cần tìm") {
                txtGiaTriTimKiem.Text = "";
            }
            Response.Redirect("~/TimKiemSach.aspx?Loai=TimKiem&GiaTri=" + txtGiaTriTimKiem.Text.Trim());
        }

        protected void lbtThoat_Click(object sender, EventArgs e)
        {
            Session.RemoveAll();
            Response.Redirect("~/Home.aspx");
        }
    }
}